#region (c) 2014 THN Solutions LLC. - All rights reserved
/*
Simplified BSD License (BSD)
Copyright (c) 2014, THN Solutions LLC. ( www.ThnSolutions.com )
Author: Nguyễn, M. Hải                 ( www.Minh-Hai.com     )
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this 
      list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright notice, 
      this list of conditions and the following disclaimer in the documentation 
      and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

using System;
using System.Drawing;

namespace Thn.Drawing
{
    public class CymkColor
    {
        #region Properties

        float mc;
        float mm;
        float my;
        float mk;

        private byte mAlpha;
        /// <summary>
        /// Gets/Sets the alpha component. Actually this is not in CYMK space
        /// </summary>
        public byte Alpha
        {
            get { return mAlpha; }
            set { mAlpha = value; }
        }


        public float Cyan
        {
            get { return mc; }
            set
            {
                mc = value;
                mc = mc > 1 ? 1 : mc < 0 ? 0 : mc;
            }
        }

        public float Magenta
        {
            get { return mm; }
            set
            {
                mm = value;
                mm = mm > 1 ? 1 : mm < 0 ? 0 : mm;
            }
        }

        public float Yellow
        {
            get { return my; }
            set
            {
                my = value;
                my = my > 1 ? 1 : my < 0 ? 0 : my;
            }
        }

        public float Black
        {
            get { return mk; }
            set
            {
                mk = value;
                mk = mk > 1 ? 1 : mk < 0 ? 0 : mk;
            }
        }

        #endregion

        #region Constructor
        public CymkColor()
        {
            mc = 0;
            mm = 0;
            my = 0;
            mk = 0;
        }
        #endregion

        #region Casting
        #region CYMK <-> Argb
        public static implicit operator Color(CymkColor cymk)
        {
            return ColorConverter.CYMKmtomArgb(cymk);
        }

        public static implicit operator CymkColor(Color c)
        {
            return ColorConverter.ArgbmtomCYMK(c);
        }
        #endregion

        #region CYMK -> HSL
        public static implicit operator HslColor(CymkColor cymk)
        {
            Color c = ColorConverter.CYMKmtomArgb(cymk);
            return ColorConverter.ArgbmtomHSL(c);
        }
        #endregion
        #endregion
    }
}
